package com.gps.skyrc.tool;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.gps.skyrc.R;

import java.util.Objects;

/**
 * Create by ywq
 * data 2018/12/13
 */
public class TwoChooseDialog extends Dialog {

    private String info;
    private String mPromptHint;
    private TwoClickListener mOnClickListener;
    private TextView mCancel;
    private TextView mHintTv;
    private TextView mConfirmTv;

    public TwoChooseDialog(@NonNull Context context,String info,String confirmHint) {
        super(context);
        this.info = info;
        this.mPromptHint = confirmHint;
    }

    public void setClickListener(TwoClickListener onClickListener){
        this.mOnClickListener = onClickListener;
    }

    public interface TwoClickListener{
        void confirm();

        void cancel();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        Objects.requireNonNull(getWindow()).setBackgroundDrawable(new BitmapDrawable());

        setContentView(R.layout.two_choose_dialog);
        //按空白处不能取消动画
        setCanceledOnTouchOutside(false);
        //初始化界面控件
        initView();
        //初始化界面数据
        initData();
        //初始化界面控件的事件
        initEvent();
    }

    private void initView() {
        mHintTv = findViewById(R.id.hint);
        mCancel = findViewById(R.id.cancel);
        mConfirmTv = findViewById(R.id.confirm);
    }

    private void initData() {
        mHintTv.setText(info);
        mConfirmTv.setText(mPromptHint);
    }

    private void initEvent() {
        mCancel.setOnClickListener(v -> {
            if (mOnClickListener != null)
                mOnClickListener.cancel();
        });

        mConfirmTv.setOnClickListener(v -> {
            if (mOnClickListener != null)
                mOnClickListener.confirm();
        });
    }
}
